<%@page import="pro.syj.dao.ManagerDao"%>
<%@page import="pro.syj.bean.Manager"%>
<%@page import="pro.syj.bean.Student"%>
<%@page import="pro.syj.dao.StudentDao"%>
<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%
    // 获取绝对路径
    String path = request.getContextPath();
    String basePath = request.getScheme() + "://" + request.getServerName() + ":"
                + request.getServerPort() + path + "/";
%>

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
	<base href="<%=basePath %>"/>
	<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
	<title>登录验证</title>
	<link rel='stylesheet' href='CSS/decorator1.css'>
</head>

<body>
	<%
	    // 设置接收的编码为UTF-8
	    request.setCharacterEncoding("utf-8");
	    
		String identity = request.getParameter("identity");
	    String id = request.getParameter("username");
	    String psd = request.getParameter("password");
	
		if("student".equals(identity)){
			Student student = new Student();
			StudentDao studentdao = new StudentDao();
			if(studentdao.isValid(id, psd)==1){
				student = studentdao.selectOne2(id);
				session.setAttribute("student", student);
				response.sendRedirect("studentMain.jsp");
			}else{
				response.sendRedirect("loginFailure.jsp");
			}
		}
		else if("manager".equals(identity)){
			Manager manager = new Manager();
			ManagerDao managerdao = new ManagerDao();
			if(managerdao.isValid(id, psd)==1){
				manager = managerdao.selectOne(id);
				session.setAttribute("manager", manager);
				response.sendRedirect("managerMain.jsp");
			}else{
				response.sendRedirect("loginFailure.jsp");
			}
		}
	
	%>
</body>
</html>